﻿//Dùng tại frmNhapVeHuy_DL (nút in tổng hợp) và frmNhapVeHuy_CB (nút tin chi tiết)

using System;
using System.Data;
using System.Data.SqlClient;
using DevExpress.XtraReports.UI;
using prjKQXS_DLL;

namespace prjKQXS_Report.Truyen_thong
{
    public partial class rptTongHopTT : DevExpress.XtraReports.UI.XtraReport
    {
        public DataTable dtSource;
        public string TyLe = "";

        public rptTongHopTT()
        {
            InitializeComponent();
        }

        private void rptTongHopTT_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Report_DAL report_dal = new Report_DAL();
            dsReports dsReports1 = new dsReports();
            dsReports1 = report_dal.reportDungChung(dsReports1);

            xrlblTenDV1.Text = "PHÒNG XSKT " + pTenDV.Value.ToString().Trim();
            xrlblTenDV2.Text = "PHÒNG XSKT " + pTenDV.Value.ToString().Trim();
            xrlblKyHieu1.Text = "Ký hiệu: " + pKyHieu.Value.ToString().Trim();
            xrlblKyHieu2.Text = "Ký hiệu: " + pKyHieu.Value.ToString().Trim();
            xrlblNgay1.Text = "Mở thưởng ngày: " + ((DateTime)pNgayMoThuong.Value).ToString("dd/MM/yyyy");
            xrlblNgay2.Text = "Mở thưởng ngày: " + ((DateTime)pNgayMoThuong.Value).ToString("dd/MM/yyyy");

            xuly(ref dtSource);// hiện doanh thu bằng chữ 17.02.2014
            lblHT.Text = lblHT2.Text = TyLe;

            dsReports1.Tables.Remove("TruyenThong");
            dsReports1.Tables.Add(dtSource);
            this.DataSource = dsReports1;
            this.DataMember = "TruyenThong";
        }

        int stt = 0;
        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            xrtcSTT1.Text = (++stt).ToString();
            xrtcSTT2.Text = (stt).ToString();
        }

        private void xuly(ref DataTable dt)
        {
            decimal VeNhan = 0;
            decimal docso1 = 0;
            decimal VeBan = 0;

            foreach (DataRow row in dt.Rows)
            {
                if (row["SLVeNhan"] != null
                    && (decimal)clsCommon.Parse(row["SLVeNhan"].ToString(), 3) != 0
                    && row["SLVeNhan"].ToString() != ""
                    && row["SLVeBan"] != null)
                {
                    if (row["SLVeNhan"] == null || row["SLVeNhan"].ToString() == "")
                        row["SLVeNhan"] = "0";
                    VeNhan += (decimal)clsCommon.Parse(row["SLVeNhan"].ToString(), 3);
                    VeBan += (decimal)clsCommon.Parse(row["SLVeBan"].ToString(), 3);
                    docso1 = VeBan * (int)clsCommon.Parse(row["GiaVe"].ToString(), 0); ;
                }
            }

            if (VeNhan != 0)
            {
                lblHT.Text = (Math.Round(VeBan / VeNhan * 100, 1)).ToString();
                lblHT2.Text = lblHT.Text;
            }

            lblBangso.Text = clsCommon.Docso(docso1);
            lblBangso1.Text = lblBangso.Text;
        }
    }
}
